package com.bt.att.dao;

import java.sql.*;
import java.util.Date;

class DaoJdbcUtil {
	public static Date getDate(ResultSet rs, String columnName) throws SQLException {
		Date date = null;
        Timestamp timestamp = rs.getTimestamp(columnName);
        if (timestamp != null) {
        	date = new Date(timestamp.getTime());
        }
        
		return date;
	}

	public static void setTimestamp(PreparedStatement ps, int index, Date value) throws SQLException {
		if (value != null) {
        	ps.setTimestamp(index, new Timestamp(value.getTime()));
        } else {
        	ps.setNull(index, Types.TIMESTAMP);
        }
	}

	public static void setString(PreparedStatement ps, int index, String value) throws SQLException {
		if (value != null) {
        	ps.setString(index, value);
        } else {
        	ps.setNull(index, Types.VARCHAR);
        }
	}

	public static void setLong(PreparedStatement ps, int index, Long value) throws SQLException {
		if (value != null) {
        	ps.setLong(index, value);
        } else {
        	ps.setNull(index, Types.INTEGER);
        }
	}

	public static void setDouble(PreparedStatement ps, int index, Double value) throws SQLException {
		if (value != null) {
        	ps.setDouble(index, value);
        } else {
        	ps.setNull(index, Types.DOUBLE);
        }
	}


}
